import {
  CalculatorOutlined,
  ClockCircleOutlined,
  CopyOutlined,
  MinusSquareOutlined,
  PlusSquareOutlined,
  QuestionCircleOutlined,
} from '@ant-design/icons'
import * as mathjs from 'mathjs'
import {
  QUOTATION_NEGOTATIATE_STATE_TEXT,
  QUOTATION_NEGOTATIATE_STATUS_TEXT,
  QUOTATION_STATUS_TEXT,
} from '@/constant/goods'
import {
  Empty,
  Input,
  InputNumber,
  Select,
  Space,
  TableColumnsType,
  Tooltip,
  Typography,
  Image,
  Dropdown,
  message,
  Button,
} from 'antd'
import { NavigateFunction } from 'react-router-dom'
import type { ITableData, QuotationCraftDetailVO, QuotationExcipientsDetailVO, QuotationMainDetailVO } from './types'
import { EditOutlined, SwitcherOutlined } from '@ant-design/icons'
import { STATUSCONFIRMTEXT } from '@/constant'
import { compareObjectsByKey } from '@/utils/util'
import { INTENT_ORDER_TYPE_MAP, ORDER_STATUS_TEXT } from '@/constant/purchase'
import { getImageByUrl } from '@/utils/getImageByUrl'
import dayjs from 'dayjs'
import { ItemType, MenuItemType } from 'antd/es/menu/interface'
const grossProfitCalc = (detailInfo: any) => {
  if (!detailInfo.tagPrice || !detailInfo.negotiatePrice) return '-'
  const tagPrice = detailInfo?.tagPrice
  const negotiatePrice = detailInfo?.negotiatePrice
  try {
    // 计算毛利率 = (吊牌价 - 议价) / 吊牌价 * 100
    const rate = mathjs.chain(tagPrice).subtract(negotiatePrice).divide(tagPrice).multiply(100).done()
    return (
      mathjs.format(rate, {
        notation: 'fixed',
        precision: 2,
      }) + '%'
    )
  } catch {
    return '-'
  }
}
export const specDictVal: string[] = ['编织袋', '纸箱', '封箱胶', '利器贴', '打包带', '箱唛', '物流卡']
export const useColumns = ({
  navigate,
  handleGetColorRange,
  onViewLogs,
  onViewOrderQty,
  isRoot,
  SplitColor,
}: {
  navigate: NavigateFunction
  handleGetColorRange: (tableData: ITableData) => void
  onViewLogs: (tableData: ITableData) => void
  onViewOrderQty: (tableData: ITableData) => void
  isRoot: boolean
  SplitColor: boolean
}): TableColumnsType<ITableData> => [
  {
    title: '报价单号',
    dataIndex: 'quotationOrderCode',
    key: 'quotationOrderCode',
    align: 'center',
    width: 230,
    render: (info, rows, index) => {
      return (
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6 }}>
          <CopyOutlined
            style={{ color: 'var(--primary-color)', verticalAlign: 'middle', cursor: 'pointer' }}
            onClick={async () => {
              try {
                await navigator.clipboard.writeText(info)
                message.success('复制成功')
              } catch (error) {
                console.error('复制失败:浏览器不支持 navigator.clipboard.writeText方法', error)
              }
            }}
          />
          <Typography.Link
            ellipsis
            onClick={() => {
              window.open(
                '/goods/quotation/detail?quotationOrderCode=' + info + '&quotationOrderId=' + rows.quotationOrderId,
              )
            }}
          >
            {rows.quotationSnapshotList && rows.quotationSnapshotList.length > 0 ? (
              <div>
                <span>{info + '(' + QUOTATION_STATUS_TEXT[rows.quotationStatus!] + ')'}</span>
                <Tooltip
                  placement="top"
                  title={
                    <div style={{ display: 'flex', flexDirection: 'column' }}>
                      {rows.quotationSnapshotList.map((item: any, index: number) => {
                        return (
                          <div
                            key={item.snapshotId}
                            style={{ display: 'flex', alignItems: 'center' }}
                            onClick={(event) => {
                              event.stopPropagation()
                              window.open(
                                '/goods/quotation/detail?quotationOrderCode=' +
                                  info +
                                  '&quotationOrderId=' +
                                  rows.quotationOrderId +
                                  '&snapshotId=' +
                                  item.snapshotId,
                              )
                            }}
                          >
                            <div>版本{rows.quotationSnapshotList.length - index}：</div>
                            <div style={{ textDecoration: 'underline', cursor: 'pointer' }}>{item.createTime}</div>
                          </div>
                        )
                      })}
                    </div>
                  }
                >
                  <ClockCircleOutlined style={{ marginLeft: 4, color: '#000', verticalAlign: 'middle' }} />
                </Tooltip>
              </div>
            ) : (
              <span>{info + '(' + QUOTATION_STATUS_TEXT[rows.quotationStatus!] + ')'} </span>
            )}
          </Typography.Link>
        </div>
      )
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    align: 'center',
    width: 140,
    render: (info, rows) => {
      return info ? (
        <div>
          {dayjs(info).format('YYYY-MM-DD')}
          {rows?.quotationStatus == 0 && (
            <span style={{ color: 'red', marginLeft: 4 }}>
              ({rows?.compareTime > 0 ? rows?.compareTime + '天前' : '今天'})
            </span>
          )}
        </div>
      ) : (
        '-'
      )
    },
  },
  {
    title: '供应商',
    dataIndex: 'supplierName',
    key: 'supplierName',
    align: 'center',
    width: 160,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return (
        <Tooltip placement="top" title={info}>
          {info || '-'}
        </Tooltip>
      )
    },
  },
  {
    title: '图片',
    dataIndex: 'imageUrl',
    key: 'imageUrl',
    align: 'center',
    width: 120,
    render: (info) => {
      return (
        <Image rootClassName="table_image" width={50} height={50} src={info} fallback={getImageByUrl('moren.png')} />
      )
    },
  },
  {
    title: '设计编码',
    dataIndex: 'designCode',
    key: 'designCode',
    align: 'center',
    width: 110,
    render: (info, rows) => {
      return isRoot ? (
        <Typography.Link
          ellipsis
          onClick={() => {
            window.open('/goods/style/detail?spuDevId=' + rows.spuDevId)
          }}
          style={{ paddingLeft: 12, paddingRight: 12 }}
        >
          {info}
        </Typography.Link>
      ) : (
        info
      )
    },
  },
  {
    title: '工厂款号',
    dataIndex: 'factorySpuCode',
    key: 'factorySpuCode',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '款式编码',
    dataIndex: 'spuCode',
    key: 'spuCode',
    align: 'center',
    width: 110,
    render: (info, rows) => {
      return rows.spuCode ? (
        isRoot ? (
          <Typography.Link
            ellipsis
            onClick={() => {
              window.open('/goods/manage/detail?spuId=' + rows.spuId)
            }}
            style={{ paddingLeft: 12, paddingRight: 12 }}
          >
            {info}
          </Typography.Link>
        ) : (
          info || '-'
        )
      ) : (
        '-'
      )
    },
  },
  {
    title: '商品名称',
    dataIndex: 'spuName',
    key: 'spuName',
    align: 'center',
    width: 140,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return (
        <Tooltip placement="top" title={info}>
          {info || '-'}
        </Tooltip>
      )
    },
  },

  {
    title: '款式色',
    dataIndex: 'colourSeparation',
    key: 'colourSeparation',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return (
        <Tooltip
          placement="top"
          title={
            rows.colorDetails && rows.colorDetails.length > 0 ? (
              <div>
                {rows.colorDetails?.map((item) => {
                  return <div key={item.colorCode}>{item.colorDetailName}</div>
                })}
              </div>
            ) : null
          }
        >
          {info == 1 ? (
            <div
              className="split_color_box"
              onClick={() => {
                if (!SplitColor) return
                handleGetColorRange(rows)
              }}
            >
              {SplitColor && <SwitcherOutlined />}
              <span>分色</span>
            </div>
          ) : (
            <div
              className="split_color_box"
              onClick={() => {
                if (!SplitColor) return
                handleGetColorRange(rows)
              }}
            >
              {SplitColor && <SwitcherOutlined />}
              <span>不分色</span>
            </div>
          )}
        </Tooltip>
      )
    },
  },
  {
    title: '下单数量',
    dataIndex: 'orderQty',
    key: 'orderQty',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return info ? <Typography.Link onClick={() => onViewOrderQty(rows)}>{info}</Typography.Link> : '-'
    },
  },
  {
    title: '吊牌价',
    dataIndex: 'tagPrice',
    key: 'tagPrice',
    align: 'center',
    width: 100,
    hidden: !isRoot,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: (
      <div>
        <div>企划毛利率</div>
        {isRoot && <div>毛利率下限</div>}
      </div>
    ),
    dataIndex: 'a1',
    key: 'a1',
    align: 'center',
    width: 100,
    hidden: !isRoot,
    render: (_, rows) => {
      return (
        <div>
          <div>{rows.planRate ? rows.planRate + '%' : '-'}</div>
          {isRoot && <div>{rows.profitRateLowerLimit ? rows.profitRateLowerLimit + '%' : '-'}</div>}
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>最新议价</div>
        {isRoot && <div>当前毛利率</div>}
      </div>
    ),
    dataIndex: 'negotiatePrice',
    key: 'negotiatePrice',
    align: 'center',
    width: 100,
    render: (_, rows) => {
      return (
        <div>
          <div>{rows.negotiatePrice || '-'}</div>
          {isRoot && <div>{rows?.negotiatePriceProfitRate ? rows?.negotiatePriceProfitRate + '%' : '-'}</div>}
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>最新报价</div>
        {isRoot && <div>报价毛利率</div>}
      </div>
    ),
    dataIndex: 'quotationPrice',
    key: 'quotationPrice',
    align: 'center',
    width: 100,
    render: (_, rows) => {
      return (
        <div>
          <div>{rows.quotationPrice || '-'}</div>
          {isRoot && <div>{rows?.quotationPriceProfitRate ? rows?.quotationPriceProfitRate + '%' : '-'}</div>}
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>最新核价</div>
        {isRoot && <div>核价毛利率</div>}
      </div>
    ),
    dataIndex: 'checkPrice',
    key: 'checkPrice',
    align: 'center',
    width: 100,
    render: (_, rows) => {
      return (
        <div>
          <div>{rows.checkPrice || '-'}</div>
          {isRoot && <div>{rows?.checkPriceProfitRate ? rows?.checkPriceProfitRate + '%' : '-'}</div>}
        </div>
      )
    },
  },
  {
    title: '大类',
    dataIndex: 'bigClassName',
    key: 'bigClassName',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '采购方式',
    dataIndex: 'purchaseType',
    key: 'purchaseType',
    align: 'center',
    width: 100,
    render: (info) => {
      return info == 0 ? '集采' : info == 1 ? '现采' : '-'
    },
  },
  {
    title: '报价阶段',
    dataIndex: 'quotationStage',
    key: 'quotationStage',
    align: 'center',
    width: 100,
    hidden: !isRoot,
    render: (info) => {
      return QUOTATION_NEGOTATIATE_STATE_TEXT[info] || '-'
    },
  },
  {
    title: '议价状态',
    dataIndex: 'negotiateStatus',
    key: 'negotiateStatus',
    align: 'center',
    width: 100,
    render: (info) => {
      return QUOTATION_NEGOTATIATE_STATUS_TEXT[info] || '-'
    },
  },
  {
    title: '确认时间',
    dataIndex: 'confirmTime',
    key: 'confirmTime',
    align: 'center',
    width: 120,
    render: (info) => {
      return info ? dayjs(info).format('YYYY-MM-DD') : '-'
    },
  },
  {
    title: '报价人',
    dataIndex: 'quotationPerson',
    key: 'quotationPerson',
    align: 'center',
    width: 100,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '设计师/买手',
    dataIndex: 'designerName',
    key: 'designerName',
    align: 'center',
    width: 100,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '核价员',
    dataIndex: 'checkPerson',
    key: 'checkPerson',
    align: 'center',
    width: 100,
    render: (info) => {
      return info ? info : '-'
    },
  },

  {
    title: '操作',
    dataIndex: 'operation',
    key: 'operation',
    align: 'center',
    width: 120,
    fixed: 'right',
    render: (_, rows) => {
      return (
        <Space size="large">
          <Typography.Link onClick={() => onViewLogs(rows)}>查看日志</Typography.Link>
        </Space>
      )
    },
  },
]

export const useMMDColumns = ({
  snapshotId,
  DICTDATA,
  tableData,
  settableData,
  inputRef,
  FabricOption,
  handleSearchFabric,
  SupplierOption,
  handleSearchSupplier,
  onSave,
  historyLatestInfo,
  detailInfo,
  showQuotationEdit,
  showCheckQuotationEdit,
  showAddBtn,
  showDelBtn,
  showAction,
  showBaseEdit,
}: {
  snapshotId: boolean
  DICTDATA: IDICTDATAType
  tableData: QuotationMainDetailVO[]
  inputRef: React.MutableRefObject<any>
  settableData: React.Dispatch<React.SetStateAction<QuotationMainDetailVO[]>>
  FabricOption: IOptionItem[]
  handleSearchFabric: (
    newVal: string,
    devSeason?: number,
    bigClassId?: number[] | string,
    intensiveStatus?: 0 | 1,
  ) => void
  SupplierOption: IOptionItem[]
  handleSearchSupplier: (newVal: string) => void
  onSave: (data: QuotationMainDetailVO[]) => void
  historyLatestInfo: Record<string, any>
  detailInfo: Record<string, any>
  showQuotationEdit: boolean
  showCheckQuotationEdit: boolean
  showAddBtn: boolean
  showDelBtn: boolean
  showAction: boolean
  showBaseEdit: boolean
}): TableColumnsType<QuotationMainDetailVO> => [
  {
    title: '操作',
    dataIndex: 'cz',
    key: 'cz',
    align: 'center',
    width: 100,
    render: (_, __, index) => {
      return (
        <Space
          size="small"
          style={{
            visibility: showAction ? 'visible' : 'hidden',
          }}
        >
          {showDelBtn && (
            <Typography.Link>
              <MinusSquareOutlined
                style={{ color: 'var(--error-color)' }}
                onClick={() => {
                  console.log('删除操作')
                  tableData.splice(index, 1)
                  settableData([...tableData])
                  onSave([...tableData])
                }}
              />
            </Typography.Link>
          )}
          {index === tableData.length - 1 && showAddBtn && (
            <Dropdown
              onOpenChange={(show) => {
                setTimeout(() => {
                  show && inputRef.current?.focus()
                }, 400)
              }}
              menu={{
                items: [
                  {
                    key: 'addbtn',
                    label: (
                      <div
                        className="spec_input_drop_down"
                        style={{ display: 'flex', alignItems: 'center', gap: 6 }}
                        onClick={() => {
                          const val = inputRef?.current?.input?.value || 1
                          for (let index = 1; index <= val; index++) {
                            tableData.push({
                              tempId: index + new Date().getTime(),
                              isEdit: true,
                            })
                          }
                          settableData([...tableData])
                        }}
                      >
                        添加
                        <Input
                          ref={inputRef}
                          className="spec_input_drop_down"
                          style={{ width: 60, lineHeight: 0, height: 24 }}
                          defaultValue={1}
                          onClick={(event) => {
                            event.stopPropagation()
                          }}
                          onPressEnter={(event: any) => {
                            const val = event?.target?.value
                            for (let index = 1; index <= val; index++) {
                              tableData.push({
                                tempId: index + new Date().getTime(),
                                isEdit: true,
                              })
                            }
                            settableData([...tableData])
                          }}
                        ></Input>
                        行
                      </div>
                    ),
                  },
                ],
              }}
            >
              <Typography.Link>
                <PlusSquareOutlined />
              </Typography.Link>
            </Dropdown>
          )}
        </Space>
      )
    },
  },

  {
    title: (
      <div>
        <div>是否</div>
        <div>集约</div>
      </div>
    ),
    dataIndex: 'intensiveStatus',
    key: 'intensiveStatus',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Select
            status={rows.intensiveStatus == undefined ? 'error' : undefined}
            value={info}
            options={[
              { label: '是', value: 1 },
              { label: '否', value: 0 },
            ]}
            onChange={(val) => {
              rows.intensiveStatus = val
              rows.materialsCode = null
              rows.fabricName = null
              settableData([...tableData])
            }}
          ></Select>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'intensiveStatus',
              )
                ? ''
                : 'red',
            }}
          >
            {STATUSCONFIRMTEXT[info] || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>使用</div>
        <div>部位</div>
      </div>
    ),
    dataIndex: 'useSite',
    key: 'useSite',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            status={!rows.useSite ? 'error' : undefined}
            onChange={(event) => {
              rows.useSite = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'useSite',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '面料名称',
    dataIndex: 'fabricName',
    key: 'fabricName',
    align: 'center',
    width: 140,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          {rows.intensiveStatus ? (
            <Select
              status={!rows.fabricName ? 'error' : undefined}
              onSearch={(newVal) => {
                handleSearchFabric(newVal, detailInfo?.seasonName, detailInfo?.bigClassId, 1)
              }}
              onChange={(_, item: any) => {
                rows.fabricName = item?.label
                if (rows.intensiveStatus == 1) {
                  rows.materialsCode = item?.code
                  rows.fabricSupplier = item?.supplierNames
                  rows.fabricSpec = item?.yarnSpec
                  rows.fabricComposition = item?.fabricComposition
                  rows.fabricBreadth = item?.fabricBreadth
                  rows.gramWeight = item?.gramWeight
                }
                settableData([...tableData])
              }}
              value={info || null}
              options={FabricOption}
              style={{ maxWidth: 120 }}
              popupMatchSelectWidth={false}
              suffixIcon={null}
              showSearch={true}
              filterOption={false}
              optionFilterProp="label"
              notFoundContent={<Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />}
            ></Select>
          ) : (
            <Input
              value={info || null}
              status={!rows.fabricName ? 'error' : undefined}
              onChange={(event) => {
                rows.fabricName = event.target.value
                settableData([...tableData])
              }}
            ></Input>
          )}
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'fabricName',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '面料供应商',
    dataIndex: 'fabricSupplier',
    key: 'fabricSupplier',
    align: 'center',
    width: 140,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          {rows.intensiveStatus ? (
            <Select
              value={info || null}
              onSearch={(newVal) => {
                handleSearchSupplier(newVal)
              }}
              onChange={(_, item: any) => {
                rows.fabricSupplier = item?.label
                settableData([...tableData])
              }}
              status={!rows.fabricSupplier ? 'error' : undefined}
              options={SupplierOption}
              style={{ maxWidth: 120 }}
              popupMatchSelectWidth={false}
              suffixIcon={null}
              showSearch={true}
              filterOption={false}
              optionFilterProp="label"
              notFoundContent={<Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />}
            ></Select>
          ) : (
            <Input
              value={info || null}
              status={!rows.fabricSupplier ? 'error' : undefined}
              onChange={(event) => {
                rows.fabricSupplier = event.target.value
                settableData([...tableData])
              }}
            ></Input>
          )}
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'fabricSupplier',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '规格',
    dataIndex: 'fabricSpec',
    key: 'fabricSpec',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.fabricSpec = event.target.value
              settableData([...tableData])
            }}
            status={!rows.fabricSpec ? 'error' : undefined}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'fabricSpec',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '成分',
    dataIndex: 'fabricComposition',
    key: 'fabricComposition',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.fabricComposition = event.target.value
              settableData([...tableData])
            }}
            status={!rows.fabricComposition ? 'error' : undefined}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'fabricComposition',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>幅宽</div>
        <div>（cm）</div>
      </div>
    ),
    dataIndex: 'fabricBreadth',
    key: 'fabricBreadth',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.fabricBreadth = event.target.value
              settableData([...tableData])
            }}
            status={!rows.fabricBreadth ? 'error' : undefined}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'fabricBreadth',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>克重</div>
        <div>（g/m²）</div>
      </div>
    ),
    dataIndex: 'gramWeight',
    key: 'gramWeight',
    align: 'center',
    width: 110,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.gramWeight = event.target.value
              settableData([...tableData])
            }}
            status={!rows.gramWeight ? 'error' : undefined}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'gramWeight',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单位',
    dataIndex: 'unit',
    key: 'unit',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Select
            options={DICTDATA.fabric_unit}
            showSearch
            value={info || null}
            onChange={(val) => {
              rows.unit = val
              settableData([...tableData])
            }}
            status={!rows.unit ? 'error' : undefined}
          ></Select>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'unit',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '净单耗',
    dataIndex: 'unitConsumption',
    key: 'unitConsumption',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledunitConsumptionAndwaste}
            status={!rows.unitConsumption ? 'error' : undefined}
            onChange={(val) => {
              rows.unitConsumption = val
              if (rows.unitConsumption || rows.waste) {
                rows.disabledunitUsedNum = true
                rows.unitUsedNum = mathjs.format(
                  mathjs.multiply(
                    mathjs.bignumber(rows.unitConsumption || 0),
                    mathjs.bignumber(1 + Number(rows.waste || 0) / 100),
                  ),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              } else {
                rows.disabledunitUsedNum = false
                rows.unitUsedNum = null
              }
              if (rows?.unitPrice && rows?.unitPrice > 0 && rows?.unitUsedNum && Number(rows?.unitUsedNum) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'unitConsumption',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '损耗(%)',
    dataIndex: 'waste',
    key: 'waste',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={2}
            value={info || 0}
            disabled={rows.disabledunitConsumptionAndwaste}
            status={!rows.waste ? 'error' : undefined}
            onChange={(val) => {
              rows.waste = val ? val + '' : 0
              if (rows.unitConsumption || rows.waste) {
                rows.disabledunitUsedNum = true
                rows.unitUsedNum = mathjs.format(
                  mathjs.multiply(
                    mathjs.bignumber(rows.unitConsumption || 0),
                    mathjs.bignumber(1 + Number(rows.waste || 0) / 100),
                  ),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              } else {
                rows.disabledunitUsedNum = false
                rows.unitUsedNum = null
              }
              if (rows?.unitPrice && rows?.unitPrice > 0 && rows?.unitUsedNum && Number(rows?.unitUsedNum) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'waste',
              )
                ? ''
                : 'red',
            }}
          >
            {info >= 0 ? Number(info) + '%' : '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>单件</div>
        <div>用量</div>
      </div>
    ),
    dataIndex: 'unitUsedNum',
    key: 'unitUsedNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={6}
            status={!rows.unitUsedNum ? 'error' : undefined}
            disabled={rows?.disabledunitUsedNum}
            value={info || null}
            onChange={(val) => {
              rows.unitUsedNum = val
              rows.unitConsumption = '0'
              rows.waste = '0'
              if (rows?.unitPrice && rows?.unitPrice > 0 && rows?.unitUsedNum && Number(rows?.unitUsedNum) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              rows.disabledunitConsumptionAndwaste = !!rows.unitUsedNum
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'unitUsedNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单价',
    dataIndex: 'unitPrice',
    key: 'unitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            status={!rows.unitPrice ? 'error' : undefined}
            precision={4}
            value={info || null}
            disabled={rows.disabledunitPrice}
            onChange={(val) => {
              rows.unitPrice = val
              rows.disabledMoney = !!val
              if (rows?.unitPrice && rows?.unitPrice > 0 && rows?.unitUsedNum && Number(rows?.unitUsedNum) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'unitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '金额',
    dataIndex: 'money',
    key: 'money',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            status={!rows.money ? 'error' : undefined}
            disabled={rows.disabledMoney}
            value={info || null}
            onChange={(val) => {
              rows.money = val
              rows.disabledunitPrice = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'money',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div>
        <div>工厂</div>
        <div>备注</div>
      </div>
    ),
    dataIndex: 'factoryRemark',
    key: 'factoryRemark',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.factoryRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'factoryRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>用量</div>
      </div>
    ),
    dataIndex: 'checkUsedNum',
    key: 'checkUsedNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={6}
            value={info || null}
            onChange={(val) => {
              rows.checkUsedNum = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'checkUsedNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>单价</div>
      </div>
    ),
    dataIndex: 'checkUnitPrice',
    key: 'checkUnitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckUnitPrice}
            onChange={(val) => {
              rows.checkUnitPrice = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              rows.disabledcheckMoney = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'checkUnitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>金额</div>
      </div>
    ),
    dataIndex: 'checkMoney',
    key: 'checkMoney',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckMoney}
            onChange={(val) => {
              rows.checkMoney = val
              rows.checkUsedNum = ''
              rows.checkUnitPrice = ''
              rows.disabledcheckUnitPrice = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'checkMoney',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>七色纺</div>
        <div>备注</div>
      </div>
    ),
    dataIndex: 'sevenfunRemark',
    key: 'sevenfunRemark',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.sevenfunRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationMainDetailList?.[index],
                historyLatestInfo?.quotationMainDetailList?.[index],
                historyLatestInfo,
                'sevenfunRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
]
export const useAMDColumns = ({
  DICTDATA,
  qpedList: tableData,
  setqpedList: settableData,
  onSave,
  inputRef,
  snapshotId,
  historyLatestInfo,
  detailInfo,
  showQuotationEdit,
  showCheckQuotationEdit,
  showAddBtn,
  showDelBtn,
  showAction,
  showBaseEdit,
  isBras,
}: {
  DICTDATA: IDICTDATAType
  qpedList: QuotationExcipientsDetailVO[]
  setqpedList: React.Dispatch<React.SetStateAction<QuotationExcipientsDetailVO[]>>
  onSave: (data: QuotationExcipientsDetailVO[]) => void
  inputRef: React.MutableRefObject<any>
  snapshotId: boolean
  historyLatestInfo: Record<string, any>
  detailInfo: Record<string, any>
  showQuotationEdit: boolean
  showCheckQuotationEdit: boolean
  showAddBtn: boolean
  showDelBtn: boolean
  showAction: boolean
  showBaseEdit: boolean
  isBras: boolean
}): TableColumnsType<QuotationExcipientsDetailVO> => [
  {
    title: '操作',
    dataIndex: 'cz',
    key: 'cz',
    align: 'center',
    width: 100,
    render: (_, __, index) => {
      return (
        <Space
          size="small"
          style={{
            visibility: showAction ? 'visible' : 'hidden',
          }}
        >
          {showDelBtn && (
            <Typography.Link>
              <MinusSquareOutlined
                style={{ color: 'var(--error-color)' }}
                onClick={() => {
                  console.log('删除操作')
                  tableData.splice(index, 1)
                  settableData([...tableData])
                  onSave([...tableData])
                }}
              />
            </Typography.Link>
          )}
          {index === tableData.length - 1 && showAddBtn && (
            <Dropdown
              onOpenChange={(show) => {
                setTimeout(() => {
                  show && inputRef.current?.focus()
                }, 400)
              }}
              menu={{
                items: [
                  {
                    key: 'addbtn',
                    label: (
                      <div
                        className="spec_input_drop_down"
                        style={{ display: 'flex', alignItems: 'center', gap: 6 }}
                        onClick={() => {
                          const val = inputRef?.current?.input?.value || 1
                          for (let index = 1; index <= val; index++) {
                            tableData.push({
                              tempId: index + new Date().getTime(),
                              isEdit: true,
                            })
                          }
                          settableData([...tableData])
                        }}
                      >
                        添加
                        <Input
                          ref={inputRef}
                          className="spec_input_drop_down"
                          style={{ width: 60, lineHeight: 0, height: 24 }}
                          defaultValue={1}
                          onClick={(event) => {
                            event.stopPropagation()
                          }}
                          onPressEnter={(event: any) => {
                            const val = event?.target?.value
                            for (let index = 1; index <= val; index++) {
                              tableData.push({
                                tempId: index + new Date().getTime(),
                                isEdit: true,
                              })
                            }
                            settableData([...tableData])
                          }}
                        ></Input>
                        行
                      </div>
                    ),
                  },
                ],
              }}
            >
              <Typography.Link>
                <PlusSquareOutlined />
              </Typography.Link>
            </Dropdown>
          )}
        </Space>
      )
    },
  },

  {
    title: '辅料名称',
    dataIndex: 'excipientsName',
    key: 'excipientsName',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Select
            style={{ maxWidth: 120 }}
            popupMatchSelectWidth={false}
            status={!rows.excipientsName ? 'error' : undefined}
            options={!isBras ? DICTDATA.production_auxiliary_name : DICTDATA.bra_production_auxiliary_name}
            value={info || null}
            showSearch
            onChange={(val) => {
              rows.excipientsName = val
              settableData([...tableData])
            }}
          ></Select>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <Tooltip placement="top" title={info || '-'}>
            <span
              className="title_ellipsis"
              style={{
                color: compareObjectsByKey(
                  detailInfo?.quotationProduceExcipientsDetailList?.[index],
                  historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                  historyLatestInfo,
                  'excipientsName',
                )
                  ? ''
                  : 'red',
              }}
            >
              {info || '-'}
            </span>
          </Tooltip>
        </div>
      )
    },
  },
  {
    title: '规格',
    dataIndex: 'spec',
    key: 'spec',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.spec = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'spec',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单位',
    dataIndex: 'unit',
    key: 'unit',
    align: 'center',
    width: 80,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Select
            options={DICTDATA.fabric_unit}
            value={info || null}
            showSearch
            status={!rows.unit ? 'error' : undefined}
            onChange={(val) => {
              rows.unit = val
              settableData([...tableData])
            }}
          ></Select>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'unit',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '净单耗',
    dataIndex: 'unitConsumption',
    key: 'unitConsumption',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            value={info || 0}
            status={!rows.unitConsumption ? 'error' : undefined}
            disabled={rows.disabledunitConsumptionAndwaste}
            onChange={(val) => {
              rows.unitConsumption = val
              if (rows.unitConsumption || rows.waste) {
                rows.disabledunitUsedNum = true
                rows.unitUsedNum = mathjs.format(
                  mathjs.multiply(
                    mathjs.bignumber(rows.unitConsumption || 0),
                    mathjs.bignumber(1 + Number(rows.waste || 0) / 100),
                  ),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              } else {
                rows.disabledunitUsedNum = false
                rows.unitUsedNum = null
              }
              if (rows.unitConsumption && rows.unitConsumption > 0 && rows.waste && rows.waste > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'unitConsumption',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '损耗(%)',
    dataIndex: 'waste',
    key: 'waste',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={2}
            value={info || 0}
            status={!rows.waste ? 'error' : undefined}
            disabled={rows.disabledunitConsumptionAndwaste}
            onChange={(val) => {
              rows.waste = val ? val + '' : 0
              if (rows.unitConsumption || rows.waste) {
                rows.disabledunitUsedNum = true
                rows.unitUsedNum = mathjs.format(
                  mathjs.multiply(
                    mathjs.bignumber(rows.unitConsumption || 0),
                    mathjs.bignumber(1 + Number(rows.waste || 0) / 100),
                  ),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              } else {
                rows.disabledunitUsedNum = false
                rows.unitUsedNum = null
              }
              if (val) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'waste',
              )
                ? ''
                : 'red',
            }}
          >
            {info >= 0 ? Number(info) + '%' : '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单件用量',
    dataIndex: 'unitUsedNum',
    key: 'unitUsedNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={6}
            disabled={rows?.disabledunitUsedNum}
            // status={!rows.unitUsedNum ? 'error' : undefined}
            value={info || null}
            onChange={(val) => {
              rows.unitUsedNum = val
              rows.unitConsumption = '0'
              rows.waste = '0'
              if (val) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              rows.disabledunitConsumptionAndwaste = !!rows.unitUsedNum
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'unitUsedNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单价',
    dataIndex: 'unitPrice',
    key: 'unitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledunitPrice}
            status={!rows.unitPrice ? 'error' : undefined}
            onChange={(val) => {
              rows.unitPrice = val
              rows.disabledMoney = !!val
              if (rows?.unitPrice && rows?.unitPrice > 0 && rows?.unitUsedNum && Number(rows?.unitUsedNum) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'unitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '金额',
    dataIndex: 'money',
    key: 'money',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            disabled={rows.disabledMoney}
            status={!rows.money ? 'error' : undefined}
            value={info || null}
            onChange={(val) => {
              rows.money = val
              rows.unitPrice = '0'
              rows.disabledunitPrice = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'money',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '工厂备注',
    dataIndex: 'factoryRemark',
    key: 'factoryRemark',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.factoryRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'factoryRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>用量</div>
      </div>
    ),
    dataIndex: 'checkUsedNum',
    key: 'checkUsedNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={6}
            value={info || null}
            onChange={(val) => {
              rows.checkUsedNum = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'checkUsedNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>单价</div>
      </div>
    ),
    dataIndex: 'checkUnitPrice',
    key: 'checkUnitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckUnitPrice}
            onChange={(val) => {
              rows.checkUnitPrice = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              rows.disabledcheckMoney = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'checkUnitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>金额</div>
      </div>
    ),
    dataIndex: 'checkMoney',
    key: 'checkMoney',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckMoney}
            onChange={(val) => {
              rows.checkMoney = val
              rows.checkUsedNum = ''
              rows.checkUnitPrice = ''
              rows.disabledcheckUnitPrice = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'checkMoney',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>七色纺</div>
        <div>备注</div>
      </div>
    ),
    dataIndex: 'sevenfunRemark',
    key: 'sevenfunRemark',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.sevenfunRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo?.quotationProduceExcipientsDetailList?.[index],
                historyLatestInfo,
                'sevenfunRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
]

export const usebzflColumns = ({
  DICTDATA,
  qPackageedList: tableData,
  setqPackageedList: settableData,
  onSave,
  inputRef,
  snapshotId,
  historyLatestInfo,
  detailInfo,
  showQuotationEdit,
  showCheckQuotationEdit,
  showAddBtn,
  showDelBtn,
  showAction,
  showBaseEdit,
}: {
  DICTDATA: IDICTDATAType
  qPackageedList: QuotationExcipientsDetailVO[]
  setqPackageedList: React.Dispatch<React.SetStateAction<QuotationExcipientsDetailVO[]>>
  onSave: (data: QuotationExcipientsDetailVO[]) => void
  inputRef: React.MutableRefObject<any>
  snapshotId: boolean
  historyLatestInfo: Record<string, any>
  detailInfo: Record<string, any>
  showQuotationEdit: boolean
  showCheckQuotationEdit: boolean
  showAddBtn: boolean
  showDelBtn: boolean
  showAction: boolean
  showBaseEdit: boolean
}): TableColumnsType<QuotationExcipientsDetailVO> => [
  {
    title: '操作',
    dataIndex: 'cz',
    key: 'cz',
    align: 'center',
    width: 100,
    render: (_, __, index) => {
      return (
        <Space
          size="small"
          style={{
            visibility: showAction ? 'visible' : 'hidden',
          }}
        >
          {showDelBtn && (
            <Typography.Link>
              <MinusSquareOutlined
                style={{ color: 'var(--error-color)' }}
                onClick={() => {
                  console.log('删除操作')
                  tableData.splice(index, 1)
                  settableData([...tableData])
                  onSave([...tableData])
                }}
              />
            </Typography.Link>
          )}
          {index === tableData.length - 1 && showAddBtn && (
            <Dropdown
              onOpenChange={(show) => {
                setTimeout(() => {
                  show && inputRef.current?.focus()
                }, 400)
              }}
              menu={{
                items: [
                  {
                    key: 'addbtn',
                    label: (
                      <div
                        className="spec_input_drop_down"
                        style={{ display: 'flex', alignItems: 'center', gap: 6 }}
                        onClick={() => {
                          const val = inputRef?.current?.input?.value || 1
                          for (let index = 1; index <= val; index++) {
                            tableData.push({
                              tempId: index + new Date().getTime(),
                              isEdit: true,
                            })
                          }
                          settableData([...tableData])
                        }}
                      >
                        添加
                        <Input
                          ref={inputRef}
                          className="spec_input_drop_down"
                          style={{ width: 60, lineHeight: 0, height: 24 }}
                          defaultValue={1}
                          onClick={(event) => {
                            event.stopPropagation()
                          }}
                          onPressEnter={(event: any) => {
                            const val = event?.target?.value
                            for (let index = 1; index <= val; index++) {
                              tableData.push({
                                tempId: index + new Date().getTime(),
                                isEdit: true,
                              })
                            }
                            settableData([...tableData])
                          }}
                        ></Input>
                        行
                      </div>
                    ),
                  },
                ],
              }}
            >
              <Typography.Link>
                <PlusSquareOutlined />
              </Typography.Link>
            </Dropdown>
          )}
        </Space>
      )
    },
  },

  {
    title: '辅料名称',
    dataIndex: 'excipientsName',
    key: 'excipientsName',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Select
            style={{ maxWidth: 120 }}
            popupMatchSelectWidth={false}
            status={!rows.excipientsName ? 'error' : undefined}
            options={DICTDATA.packaging_auxiliary_name}
            showSearch
            value={info || null}
            onSelect={(val) => {
              if (specDictVal.includes(val)) {
                if (showBaseEdit) {
                  // 净单耗、损耗清空 特殊处理变成字符串0
                  rows.unitConsumption = '0'
                  rows.waste = '0'
                  rows.unitUsedNum =
                    detailInfo?.estimateOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.estimateOutBoxNum || 0)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  if (rows.unitUsedNum == 0) {
                    message.warning('请先维护 预估外箱数 ！')
                  }
                  //计算money
                  rows.money = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                if (showCheckQuotationEdit) {
                  rows.checkUsedNum =
                    detailInfo?.checkOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.checkOutBoxNum)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  if (rows.checkUsedNum == 0) {
                    message.warning('请先维护 核价外箱数 ！')
                  }
                  //计算checkMoney
                  rows.checkMoney = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.checkUsedNum), mathjs.bignumber(rows.checkUnitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                // 净单耗、损耗、单件用量、核价用量、置灰
                rows.fourDisabled = true
              } else {
                rows.fourDisabled = false
              }
              rows.excipientsName = val
              settableData([...tableData])
            }}
            onChange={(val) => {
              if (specDictVal.includes(val)) {
                if (showBaseEdit) {
                  // 净单耗、损耗清空 特殊处理变成字符串0
                  rows.unitConsumption = '0'
                  rows.waste = '0'
                  rows.unitUsedNum =
                    detailInfo?.estimateOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.estimateOutBoxNum || 0)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  //计算money
                  rows.money = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                if (showCheckQuotationEdit) {
                  rows.checkUsedNum =
                    detailInfo?.checkOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.checkOutBoxNum)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  //计算checkMoney
                  rows.checkMoney = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.checkUsedNum), mathjs.bignumber(rows.checkUnitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                // 净单耗、损耗、单件用量、核价用量、置灰
                rows.fourDisabled = true
              } else {
                rows.fourDisabled = false
              }
              rows.excipientsName = val
              settableData([...tableData])
            }}
          ></Select>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <Tooltip placement="top" title={info || '-'}>
            <span
              className="title_ellipsis"
              style={{
                color: compareObjectsByKey(
                  detailInfo?.quotationPackageExcipientsDetailList?.[index],
                  historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                  historyLatestInfo,
                  'excipientsName',
                )
                  ? ''
                  : 'red',
              }}
            >
              {info || '-'}
            </span>
          </Tooltip>
        </div>
      )
    },
  },
  {
    title: '规格',
    dataIndex: 'spec',
    key: 'spec',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.spec = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'spec',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单位',
    dataIndex: 'unit',
    key: 'unit',
    align: 'center',
    width: 80,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Select
            options={DICTDATA.fabric_unit}
            status={!rows.unit ? 'error' : undefined}
            showSearch
            value={info || null}
            onChange={(val) => {
              rows.unit = val
              settableData([...tableData])
            }}
          ></Select>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'unit',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '净单耗',
    dataIndex: 'unitConsumption',
    key: 'unitConsumption',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            value={info || 0}
            status={!rows.unitConsumption ? 'error' : undefined}
            disabled={rows.disabledunitConsumptionAndwaste || rows?.fourDisabled}
            onChange={(val) => {
              rows.unitConsumption = val
              if (rows.unitConsumption || rows.waste) {
                rows.disabledunitUsedNum = true
                rows.unitUsedNum = mathjs.format(
                  mathjs.multiply(
                    mathjs.bignumber(rows.unitConsumption || 0),
                    mathjs.bignumber(1 + Number(rows.waste || 0) / 100),
                  ),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              } else {
                rows.disabledunitUsedNum = false
                rows.unitUsedNum = null
              }
              if (rows.unitConsumption && rows.unitConsumption > 0 && rows.waste && rows.waste > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'unitConsumption',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '损耗(%)',
    dataIndex: 'waste',
    key: 'waste',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={2}
            value={info || 0}
            status={!rows.waste ? 'error' : undefined}
            disabled={rows.disabledunitConsumptionAndwaste || rows?.fourDisabled}
            onChange={(val) => {
              rows.waste = val ? val + '' : 0
              if (rows.unitConsumption || rows.waste) {
                rows.disabledunitUsedNum = true
                rows.unitUsedNum = mathjs.format(
                  mathjs.multiply(
                    mathjs.bignumber(rows.unitConsumption || 0),
                    mathjs.bignumber(1 + Number(rows.waste || 0) / 100),
                  ),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              } else {
                rows.disabledunitUsedNum = false
                rows.unitUsedNum = null
              }
              if (rows.unitConsumption && rows.unitConsumption > 0 && rows.waste && Number(rows.waste) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'waste',
              )
                ? ''
                : 'red',
            }}
          >
            {info >= 0 ? Number(info) + '%' : '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单件用量',
    dataIndex: 'unitUsedNum',
    key: 'unitUsedNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap form_element_wrap_flex">
          <InputNumber
            min={0}
            precision={6}
            disabled={rows?.disabledunitUsedNum || rows?.fourDisabled}
            value={info || null}
            onChange={(val) => {
              rows.unitUsedNum = val
              rows.unitConsumption = '0'
              rows.waste = '0'
              if (rows?.unitPrice && rows?.unitPrice > 0 && rows?.unitUsedNum && Number(rows?.unitUsedNum) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              rows.disabledunitConsumptionAndwaste = !!rows.unitUsedNum
              settableData([...tableData])
            }}
          ></InputNumber>
          {rows?.fourDisabled && (
            <span style={{ marginLeft: 4 }}>
              <Tooltip placement="top" title={'关联外箱数自动计算'}>
                <QuestionCircleOutlined />
              </Tooltip>
            </span>
          )}
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'unitUsedNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单价',
    dataIndex: 'unitPrice',
    key: 'unitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledunitPrice}
            status={!rows.unitPrice ? 'error' : undefined}
            onChange={(val) => {
              rows.unitPrice = val
              rows.disabledMoney = !!val
              if (rows?.unitPrice && rows?.unitPrice > 0 && rows?.unitUsedNum && Number(rows?.unitUsedNum) > 0) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.unitUsedNum), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'unitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '金额',
    dataIndex: 'money',
    key: 'money',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            disabled={rows.disabledMoney}
            status={!rows.money ? 'error' : undefined}
            value={info || null}
            onChange={(val) => {
              rows.money = val
              rows.unitPrice = '0'
              rows.disabledunitPrice = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'money',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '工厂备注',
    dataIndex: 'factoryRemark',
    key: 'factoryRemark',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.factoryRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'factoryRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>用量</div>
      </div>
    ),
    dataIndex: 'checkUsedNum',
    key: 'checkUsedNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec form_element_wrap_flex">
          <InputNumber
            min={0}
            precision={6}
            value={info || null}
            disabled={rows?.fourDisabled}
            onChange={(val) => {
              rows.checkUsedNum = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
          {rows?.fourDisabled && (
            <span style={{ marginLeft: 4 }}>
              <Tooltip placement="top" title={'关联外箱数自动计算'}>
                <QuestionCircleOutlined />
              </Tooltip>
            </span>
          )}
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'checkUsedNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>单价</div>
      </div>
    ),
    dataIndex: 'checkUnitPrice',
    key: 'checkUnitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckUnitPrice}
            onChange={(val) => {
              rows.checkUnitPrice = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              rows.disabledcheckMoney = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'checkUnitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>金额</div>
      </div>
    ),
    dataIndex: 'checkMoney',
    key: 'checkMoney',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckMoney}
            onChange={(val) => {
              rows.checkMoney = val
              rows.checkUsedNum = ''
              rows.checkUnitPrice = ''
              rows.disabledcheckUnitPrice = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'checkMoney',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>七色纺</div>
        <div>备注</div>
      </div>
    ),
    dataIndex: 'sevenfunRemark',
    key: 'sevenfunRemark',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.sevenfunRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo?.quotationPackageExcipientsDetailList?.[index],
                historyLatestInfo,
                'sevenfunRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
]
export const useqscdColumns = ({
  DICTDATA,
  qscdList: tableData,
  setqscdList: settableData,
  onSave,
  inputRef,
  snapshotId,
  historyLatestInfo,
  detailInfo,
  showQuotationEdit,
  showCheckQuotationEdit,
  showAddBtn,
  showDelBtn,
  showAction,
  showBaseEdit,
}: {
  DICTDATA: IDICTDATAType
  qscdList: QuotationCraftDetailVO[]
  setqscdList: React.Dispatch<React.SetStateAction<QuotationCraftDetailVO[]>>
  onSave: (data: QuotationCraftDetailVO[]) => void
  inputRef: React.MutableRefObject<any>
  historyLatestInfo: Record<string, any>
  detailInfo: Record<string, any>
  showQuotationEdit: boolean
  showCheckQuotationEdit: boolean
  snapshotId: boolean
  showAddBtn: boolean
  showDelBtn: boolean
  showAction: boolean
  showBaseEdit: boolean
}): TableColumnsType<QuotationCraftDetailVO> => [
  {
    title: '操作',
    dataIndex: 'cz',
    key: 'cz',
    align: 'center',
    width: 100,
    render: (_, __, index) => {
      return (
        <Space
          size="small"
          style={{
            visibility: showAction ? 'visible' : 'hidden',
          }}
        >
          {showDelBtn && (
            <Typography.Link>
              <MinusSquareOutlined
                style={{ color: 'var(--error-color)' }}
                onClick={() => {
                  console.log('删除操作')
                  tableData.splice(index, 1)
                  settableData([...tableData])
                  onSave([...tableData])
                }}
              />
            </Typography.Link>
          )}
          {index === tableData.length - 1 && showAddBtn && (
            <Dropdown
              onOpenChange={(show) => {
                setTimeout(() => {
                  show && inputRef.current?.focus()
                }, 400)
              }}
              menu={{
                items: [
                  {
                    key: 'addbtn',
                    label: (
                      <div
                        className="spec_input_drop_down"
                        style={{ display: 'flex', alignItems: 'center', gap: 6 }}
                        onClick={() => {
                          const val = inputRef?.current?.input?.value || 1
                          for (let index = 1; index <= val; index++) {
                            tableData.push({
                              tempId: index + new Date().getTime(),
                              isEdit: true,
                            })
                          }
                          settableData([...tableData])
                        }}
                      >
                        添加
                        <Input
                          ref={inputRef}
                          className="spec_input_drop_down"
                          style={{ width: 60, lineHeight: 0, height: 24 }}
                          defaultValue={1}
                          onClick={(event) => {
                            event.stopPropagation()
                          }}
                          onPressEnter={(event: any) => {
                            const val = event?.target?.value
                            for (let index = 1; index <= val; index++) {
                              tableData.push({
                                tempId: index + new Date().getTime(),
                                isEdit: true,
                              })
                            }
                            settableData([...tableData])
                          }}
                        ></Input>
                        行
                      </div>
                    ),
                  },
                ],
              }}
            >
              <Typography.Link>
                <PlusSquareOutlined />
              </Typography.Link>
            </Dropdown>
          )}
        </Space>
      )
    },
  },

  {
    title: '费用名称',
    dataIndex: 'craftPriceName',
    key: 'craftPriceName',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showBaseEdit ? (
        <div className="form_element_wrap">
          <Select
            options={DICTDATA.re_tchnics_name}
            showSearch
            status={!rows.craftPriceName ? 'error' : undefined}
            value={info || null}
            onChange={(val) => {
              if (['运输费'].includes(val)) {
                if (showBaseEdit) {
                  rows.useNum =
                    detailInfo?.estimateOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.estimateOutBoxNum)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  //计算money
                  rows.money = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.useNum), mathjs.bignumber(rows.unitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                if (showCheckQuotationEdit) {
                  rows.checkUsedNum =
                    detailInfo?.checkOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.checkOutBoxNum)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  //计算checkMoney
                  rows.checkMoney = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.checkUsedNum), mathjs.bignumber(rows.checkUnitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                // 用量、核价用量、置灰
                rows.twoDisabled = true
              } else {
                rows.twoDisabled = false
              }
              rows.craftPriceName = val
              settableData([...tableData])
            }}
            onSelect={(val) => {
              if (['运输费'].includes(val)) {
                if (showBaseEdit) {
                  rows.useNum =
                    detailInfo?.estimateOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.estimateOutBoxNum)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  if (rows.useNum == 0) {
                    message.warning('请先维护 预估外箱数 ！')
                  }
                  //计算money
                  rows.money = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.useNum), mathjs.bignumber(rows.unitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                if (showCheckQuotationEdit) {
                  rows.checkUsedNum =
                    detailInfo?.checkOutBoxNum > 0
                      ? mathjs.format(mathjs.divide(1, mathjs.bignumber(detailInfo?.checkOutBoxNum)), {
                          notation: 'fixed',
                          precision: 6,
                        })
                      : 0
                  if (rows.checkUsedNum == 0) {
                    message.warning('请先维护 核价外箱数 ！')
                  }
                  //计算checkMoney
                  rows.checkMoney = mathjs.format(
                    mathjs.multiply(mathjs.bignumber(rows.checkUsedNum), mathjs.bignumber(rows.checkUnitPrice || 0)),
                    {
                      notation: 'fixed',
                      precision: 4,
                    },
                  )
                }
                // 用量、核价用量、置灰
                rows.twoDisabled = true
              } else {
                rows.twoDisabled = false
              }
              rows.craftPriceName = val
              settableData([...tableData])
            }}
          ></Select>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'craftPriceName',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '用量',
    dataIndex: 'useNum',
    key: 'useNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap form_element_wrap_flex">
          <InputNumber
            min={0}
            precision={6}
            value={info || null}
            // status={!rows.useNum ? 'error' : undefined}
            disabled={rows.disableduseNumAndUnitPrice || rows?.twoDisabled}
            onChange={(val) => {
              rows.useNum = val
              rows.disabledMoney = !!val
              if (val) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.useNum || 0), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
          {rows?.twoDisabled && (
            <span style={{ marginLeft: 4 }}>
              <Tooltip placement="top" title={'关联外箱数自动计算'}>
                <QuestionCircleOutlined />
              </Tooltip>
            </span>
          )}
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'useNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '单价',
    dataIndex: 'unitPrice',
    key: 'unitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disableduseNumAndUnitPrice}
            status={!rows.unitPrice ? 'error' : undefined}
            onChange={(val) => {
              rows.unitPrice = val
              rows.disabledMoney = !!val
              if (val) {
                rows.money = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.useNum || 0), mathjs.bignumber(rows.unitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && showBaseEdit ? (rows.isEdit = true) : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'unitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '金额',
    dataIndex: 'money',
    key: 'money',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <InputNumber
            min={0}
            precision={4}
            disabled={rows.disabledMoney}
            value={info || null}
            // status={!rows.money ? 'error' : undefined}
            onChange={(val) => {
              rows.money = val
              rows.useNum = '0'
              rows.unitPrice = '0'
              rows.money && (rows.disableduseNumAndUnitPrice = true)
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'money',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: '工厂备注',
    dataIndex: 'factoryRemark',
    key: 'factoryRemark',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showQuotationEdit ? (
        <div className="form_element_wrap">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.factoryRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'factoryRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>用量</div>
      </div>
    ),
    dataIndex: 'checkUsedNum',
    key: 'checkUsedNum',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec form_element_wrap_flex">
          <InputNumber
            min={0}
            precision={6}
            value={info || null}
            disabled={rows?.twoDisabled}
            onChange={(val) => {
              rows.checkUsedNum = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              settableData([...tableData])
            }}
          ></InputNumber>
          {rows?.twoDisabled && (
            <span style={{ marginLeft: 4 }}>
              <Tooltip placement="top" title={'关联外箱数自动计算'}>
                <QuestionCircleOutlined />
              </Tooltip>
            </span>
          )}
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'checkUsedNum',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>单价</div>
      </div>
    ),
    dataIndex: 'checkUnitPrice',
    key: 'checkUnitPrice',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckUnitPrice}
            onChange={(val) => {
              rows.checkUnitPrice = val
              if (val) {
                rows.checkMoney = mathjs.format(
                  mathjs.multiply(mathjs.bignumber(rows.checkUsedNum || 0), mathjs.bignumber(rows.checkUnitPrice || 0)),
                  {
                    notation: 'fixed',
                    precision: 4,
                  },
                )
              }
              rows.disabledcheckMoney = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'checkUnitPrice',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>核价</div>
        <div>金额</div>
      </div>
    ),
    dataIndex: 'checkMoney',
    key: 'checkMoney',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <InputNumber
            min={0}
            precision={4}
            value={info || null}
            disabled={rows.disabledcheckMoney}
            onChange={(val) => {
              rows.checkMoney = val
              rows.checkUsedNum = ''
              rows.checkUnitPrice = ''
              rows.disabledcheckUnitPrice = !!val
              settableData([...tableData])
            }}
          ></InputNumber>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'checkMoney',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
  {
    title: (
      <div className="title_bgc_spec title_bgc_spec_column">
        <div>七色纺</div>
        <div>备注</div>
      </div>
    ),
    dataIndex: 'sevenfunRemark',
    key: 'sevenfunRemark',
    align: 'center',
    width: 120,
    render: (info, rows, index) => {
      return rows?.isEdit && !snapshotId && showCheckQuotationEdit ? (
        <div className="form_element_wrap title_bgc_spec">
          <Input
            value={info || null}
            onChange={(event) => {
              rows.sevenfunRemark = event.target.value
              settableData([...tableData])
            }}
          ></Input>
        </div>
      ) : (
        <div
          className="title_bgc_normal title_bgc_spec"
          onClick={() => {
            !rows['isEdit'] && (showQuotationEdit || showCheckQuotationEdit)
              ? (rows.isEdit = true)
              : (rows.isEdit = false)
            settableData([...tableData])
          }}
        >
          <span
            style={{
              color: compareObjectsByKey(
                detailInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo?.quotationSecondCraftDetailList?.[index],
                historyLatestInfo,
                'sevenfunRemark',
              )
                ? ''
                : 'red',
            }}
          >
            {info || '-'}
          </span>
        </div>
      )
    },
  },
]

export const useCollectColumns = ({
  collectList: tableData,
  setcollectList: settableData,
  isEditTotal,
  setisEditTotal,
  isShowA,
  editMoney,
  snapshotId,
  historyLatestInfo,
  detailInfo,
  showQuotationEdit,
  showCheckQuotationEdit,
  profitmenuItems,
  onAutoCalc,
  onAutoCalcAmode,
  isShowCalcBtn,
}: {
  snapshotId: boolean
  historyLatestInfo: Record<string, any>
  detailInfo: Record<string, any>
  showQuotationEdit: boolean
  showCheckQuotationEdit: boolean
  isShowA: boolean
  collectList: {
    id: number
    name: string
    bj: string
    hj: string
  }[]
  setcollectList: React.Dispatch<
    React.SetStateAction<
      {
        id: number
        name: string
        bj: string
        hj: string
      }[]
    >
  >
  isEditTotal: boolean
  isShowCalcBtn: boolean
  setisEditTotal: React.Dispatch<React.SetStateAction<boolean>>
  editMoney: (reqKey: string, value: string) => void
  profitmenuItems: ItemType<MenuItemType>[]
  onAutoCalc: (reqKey: string, rate: string, type: 'bj' | 'hj') => void
  onAutoCalcAmode: (reqKey: string, rate: string, type: 'bj' | 'hj') => void
}): TableColumnsType<any> => [
  {
    title: '费用项',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    width: 100,
  },
  {
    title: '报价',
    dataIndex: 'bj',
    key: 'bj',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      // 加工费
      if (rows.index === 4) {
        return getIndexToEdit(
          info,
          rows,
          tableData,
          settableData,
          isEditTotal,
          setisEditTotal,
          'bj',
          'jgfBjEdit',
          'processPrice',
          editMoney,
          snapshotId,
          showQuotationEdit,
          showCheckQuotationEdit,
          onAutoCalc,
          profitmenuItems,
          onAutoCalcAmode,
          isShowCalcBtn,
        )
      }
      // 利润
      if (rows.index === 6) {
        return getIndexToEdit(
          info,
          rows,
          tableData,
          settableData,
          isEditTotal,
          setisEditTotal,
          'bj',
          'lrBjEdit',
          'profit',
          editMoney,
          snapshotId,
          showQuotationEdit,
          showCheckQuotationEdit,
          onAutoCalc,
          profitmenuItems,
          onAutoCalcAmode,
          isShowCalcBtn,
        )
      }
      // A模式
      if (isShowA && rows.index === 7) {
        return getIndexToEdit(
          info,
          rows,
          tableData,
          settableData,
          isEditTotal,
          setisEditTotal,
          'bj',
          'amodeBjEdit',
          'aPrice',
          editMoney,
          snapshotId,
          showQuotationEdit,
          showCheckQuotationEdit,
          onAutoCalc,
          profitmenuItems,
          onAutoCalcAmode,
          isShowCalcBtn,
        )
      }
      return info || '-'
    },
  },
  {
    title: <div className="title_bgc_spec">核价</div>,
    dataIndex: 'hj',
    key: 'hj',
    align: 'center',
    width: 100,
    render: (info, rows, index) => {
      // 加工费
      if (rows.index === 4) {
        return getIndexToEdit(
          info,
          rows,
          tableData,
          settableData,
          isEditTotal,
          setisEditTotal,
          'hj',
          'jgfHjEdit',
          'checkProcessPrice',
          editMoney,
          snapshotId,
          showQuotationEdit,
          showCheckQuotationEdit,
          onAutoCalc,
          profitmenuItems,
          onAutoCalcAmode,
          isShowCalcBtn,
        )
      }
      // 利润
      if (rows.index === 6) {
        return getIndexToEdit(
          info,
          rows,
          tableData,
          settableData,
          isEditTotal,
          setisEditTotal,
          'hj',
          'lrHjEdit',
          'checkProfit',
          editMoney,
          snapshotId,
          showQuotationEdit,
          showCheckQuotationEdit,
          onAutoCalc,
          profitmenuItems,
          onAutoCalcAmode,
          isShowCalcBtn,
        )
      }
      // A模式
      if (isShowA && rows.index === 7) {
        return getIndexToEdit(
          info,
          rows,
          tableData,
          settableData,
          isEditTotal,
          setisEditTotal,
          'hj',
          'amodeHjEdit',
          'checkAPrice',
          editMoney,
          snapshotId,
          showQuotationEdit,
          showCheckQuotationEdit,
          onAutoCalc,
          profitmenuItems,
          onAutoCalcAmode,
          isShowCalcBtn,
        )
      }
      return <div className="title_bgc_spec">{info || '-'}</div>
    },
  },
]

const getIndexToEdit = (
  info: string,
  rows: any,
  tableData: any[],
  settableData: React.Dispatch<React.SetStateAction<any>>,
  isEditTotal: boolean,
  setisEditTotal: React.Dispatch<React.SetStateAction<boolean>>,
  editKey: string,
  customName: string,
  reqKey: string,
  editMoney: (reqKey: string, value: string) => void,
  snapshotId: boolean,
  showQuotationEdit: boolean,
  showCheckQuotationEdit: boolean,
  onAutoCalc: (reqKey: string, rate: string, type: 'bj' | 'hj') => void,
  profitmenuItems: ItemType<MenuItemType>[],
  onAutoCalcAmode: (reqKey: string, rate: string, type: 'bj' | 'hj') => void,
  isShowCalcBtn: boolean,
) => {
  return (
    <Space size={'large'} className={editKey === 'hj' ? 'title_bgc_spec' : ''}>
      {!rows[customName] ? (
        <div style={{ display: 'flex', alignItems: 'center' }}>
          <span>{info || '-'}</span>
          {!(
            snapshotId ||
            (editKey === 'bj' && !showQuotationEdit) ||
            (editKey === 'hj' && !showCheckQuotationEdit)
          ) ? (
            <div style={{ display: 'flex', alignItems: 'center' }}>
              <EditOutlined
                style={{ color: 'var(--primary-color)', cursor: 'pointer', margin: '0 6px' }}
                onClick={() => {
                  rows[customName] = true
                  settableData([...tableData])
                }}
              />
              {isShowCalcBtn && (reqKey == 'profit' || reqKey == 'checkProfit') && (
                <Dropdown
                  menu={{
                    items: profitmenuItems,
                    onClick: (item) => onAutoCalc(reqKey, item.key!, editKey as 'bj' | 'hj'),
                  }}
                  placement="bottomLeft"
                >
                  <CalculatorOutlined style={{ cursor: 'pointer' }} />
                </Dropdown>
              )}
              {isShowCalcBtn && (reqKey == 'aPrice' || reqKey == 'checkAPrice') && (
                <Dropdown
                  menu={{
                    items: [{ label: '13%(成本+利润)', key: '0.13' }],
                    onClick: (item) => onAutoCalcAmode(reqKey, item.key!, editKey as 'bj' | 'hj'),
                  }}
                  placement="bottomLeft"
                >
                  <CalculatorOutlined style={{ cursor: 'pointer' }} />
                </Dropdown>
              )}
            </div>
          ) : null}
        </div>
      ) : (
        <Space>
          <div style={{ marginLeft: 16, marginRight: 16 }}>
            <InputNumber
              autoFocus
              precision={
                reqKey == 'profit' || reqKey == 'checkProfit' || reqKey == 'aPrice' || reqKey == 'checkAPrice' ? 4 : 2
              }
              min={0}
              defaultValue={rows[editKey] || 0}
              onBlur={() => {
                rows[customName] = false
                settableData([...tableData])
                editMoney(reqKey, rows[editKey])
              }}
              onChange={(val) => {
                rows[editKey] = val
                setisEditTotal(!isEditTotal)
                settableData([...tableData])
              }}
            ></InputNumber>
          </div>
        </Space>
      )}
    </Space>
  )
}

export const useOrderQtyColumns = (): TableColumnsType<ITableData> => [
  {
    title: '意向采购单号',
    dataIndex: 'intentOrderCode',
    key: 'intentOrderCode',
    align: 'center',
    width: 180,
    render: (info, rows) => {
      return info ? info + '（' + INTENT_ORDER_TYPE_MAP[rows?.intentOrderStatus] + '）' : '-'
    },
  },
  {
    title: '采购单号',
    dataIndex: 'purchaseOrderCode',
    key: 'purchaseOrderCode',
    align: 'center',
    width: 180,
    render: (info, rows) => {
      return info ? info + '（' + ORDER_STATUS_TEXT[rows?.purchaseOrderStatus] + '）' : '-'
    },
  },
  {
    title: '意向订单时间',
    dataIndex: 'intentOrderTime',
    key: 'intentOrderTime',
    align: 'center',
    width: 100,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '正式订单时间',
    dataIndex: 'officialOrderTime',
    key: 'officialOrderTime',
    align: 'center',
    width: 100,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '下单数量',
    dataIndex: 'orderQty',
    key: 'orderQty',
    align: 'center',
    width: 100,
    render: (info) => {
      return info ? info : '-'
    },
  },
]
